package app.web.visual.tags;

import cn.lily.com.exception.YaconException;
import cn.lily.web.page.BusinessPage;
import cn.lily.web.widget.sql.TSqlGrid;
import cn.lily.web.widget.standard.TButton;
import cn.lily.web.widget.standard.TButtonPilot;
/**
 * 标签弹窗
 * @author JiaJ
 *
 */
public class TagWindow extends BusinessPage { 

	 public void page_onLoad() throws YaconException {

		 String tag_typ_id = this.getAttr("type_id");
		 
		 TSqlGrid tagMainGrid = sqlGrid("tagMainGrid");
		 tagMainGrid.setDictTable("LEO_TAG");
		 String sqlString = "select TAG_ID,TAG_NAM,to_char(CREATE_TIME,'yyyy-mm-dd hh24:mi:ss') CREATE_TIME,CREATE_OPER "
					 	  + "from ${schema}.LEO_TAG "
					 	  + "where TAG_ID not in (select TAG_ID from LEO_TAG_TYP_RELA where TAG_TYP_ID='"+tag_typ_id+"')";
		 tagMainGrid.setCommSqlStr(sqlString);
		 tagMainGrid.setEdit(true);
		 tagMainGrid.setExcuteMethod("save");
		 tagMainGrid.setRefreshMethod("refresh");

		 tagMainGrid.createFieldTitle("TAG_ID").setFieldVisible(false);
		 tagMainGrid.createFieldTitle("TAG_NAM");
		 tagMainGrid.createFieldTitle("CREATE_TIME");
		 tagMainGrid.createFieldTitle("CREATE_OPER").setFieldVisible(false);

		 TButtonPilot tagMainPilot = ButtonPilot("tagMainPilot");
		 tagMainPilot.setPilotIco("/widget/buttonPilot.gif");
		 tagMainPilot.setPilotText("标签信息表信息");
		 
		 //按钮添加
		 TButton saveButton = Button("saves");
		 saveButton.setIcoPath("glyphicon glyphicon-floppy-saved");
		 saveButton.setLabel("确定");
		 saveButton.setViewClick("saves_onclick");
		 tagMainPilot.addButtons(saveButton);

		 tagMainGrid.setButtonPilot(tagMainPilot);
		 
		 tagMainGrid.setTopButtonType("all");
		 
		 getPage().addElement(tagMainGrid);

	 }

	 public void refresh() throws YaconException {
		 
		 String tag_typ_id = this.getViewTable().getAttributeValue("type_id");

		 TSqlGrid tagMainGrid = sqlGrid("tagMainGrid");
		 String sqlString = "select TAG_ID,TAG_NAM,to_char(CREATE_TIME,'yyyy-mm-dd hh24:mi:ss') CREATE_TIME,CREATE_OPER,'"+tag_typ_id+"' as TAG_TYP_ID "
					 	  + "from ${schema}.LEO_TAG "
					 	  + "where TAG_ID not in (select TAG_ID from LEO_TAG_TYP_RELA where TAG_TYP_ID='"+tag_typ_id+"')";
		 tagMainGrid.setCommSqlStr(sqlString);
		 this.setSelfMessage(tagMainGrid.getDataElement());

	 }

	 public void save() throws YaconException {

		 this.setSuccess("数据操作成功！");

	 }


}
